package com.zyf.school.manager.controller;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@RequestMapping("/")
public class BaseController {
    @RequestMapping(value = "{url}")
    public String baseUrl(@PathVariable String url){
        return url;
    }
    @RequestMapping(value = "{url1}/{url2}")
    public String baseUrl(@PathVariable String url1,@PathVariable String url2){
        return url1+"/"+url2;
    }
    @InitBinder
    public void initBinder(ServletRequestDataBinder binder) {
        //只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),
                true));
    }
}

